API Documentation
Public Member Functions | List of all members
nkAstraeus::MaterialManager Class Referencefinal

Manages the materials available in the component. More...

Inheritance diagram for nkAstraeus::MaterialManager:

Public Member Functions

MaterialcreateOrRetrieve (const std::string_view &name, MATERIAL_TYPE type)
 
Materialget (const std::string_view &name)
 
MaterialgetByIndex (unsigned int id)
 
void rename (const std::string_view &currentName, const std::string_view &newName)
 
void erase (const std::string_view &name)
 

Detailed Description

Manages the materials available in the component.

At all times, manager owns any memory allocated inside. External code should never delete memory returned by it.

Member Function Documentation

◆ createOrRetrieve()

Material* nkAstraeus::MaterialManager::createOrRetrieve ( const std::string_view &  name,
MATERIAL_TYPE  type 
)

Creates if unavailable, or retrieves if available, a material.

Depending on the parameter given for the type, the Material instance retrieved will be :

ValuePointer type
MATERIAL_TYPE::PBSPbsMaterial

To address it fully, casting is required. For instance :

PbsMaterial* mat = (PbsMaterial*)MaterialManager::getInstance()->createOrRetrieve("mat", MATERIAL_TYPE::PBS) ;
Parameters
nameThe name of the material to retrieve.
typeThe material type to create.
Returns
The material requested, possibly freshly created. The manager owns the memory returned, external code should never delete it. See erase().

◆ get()

Material* nkAstraeus::MaterialManager::get ( const std::string_view &  name)

Retrieves a material.

Parameters
nameThe name of the material to retrieve.
Returns
The material requested if available, nullptr else.

◆ getByIndex()

Material* nkAstraeus::MaterialManager::getByIndex ( unsigned int  id)

Get a material, by index. Note that one index can map to a different material after memory is changed. Useful to loop over all available materials in one go.

Parameters
idThe index of the material to retrieve.
Returns
The material linked if available, nullptr else.

◆ rename()

void nkAstraeus::MaterialManager::rename ( const std::string_view &  currentName,
const std::string_view &  newName 
)

Renames a material.

Parameters
currentNameThe name of the material to rename.
newNameThe name to reassign to the material.

◆ erase()

void nkAstraeus::MaterialManager::erase ( const std::string_view &  name)

Erases and frees a material.

Parameters
nameThe name of the material to erase.

The documentation for this class was generated from the following file: